'''
Created on May 22, 2011

@author: GSE
'''

 
from WebCrawl import Webcrawler,Content
 
print "Fetching data"
spider = Webcrawler()
json = spider.getTheaterMovies(15)

link = ""
movieJson = ""
movies = []

spider.openDBConn("127.0.0.1",3306, "root", "root", "cr_database")
spider.cleanTheaters(spider.conn)

for i in json:
    link= i["links"]["self"] 
    movieJson = spider.getMovieByLink(link)
    title = movieJson["title"]
    title = title.replace("'s","s")
    year = movieJson["year"]
    genre = movieJson["genres"][0]
    pic = movieJson['posters']['detailed']
    spider.pushTheatersDatabase(spider.conn,title,str(year),genre,pic)
    
spider.closeDbConn()
#
for j in movies:
    print j.toStr()
    print "\n"
    #j.pushToDatabase(spider.conn)
    
print "done, cleaning up"
#  